package com.mall.malladminbackend.controller;

import com.mall.malladminbackend.entity.Category;
import com.mall.malladminbackend.entity.GridCategory;
import com.mall.malladminbackend.model.R;
import com.mall.malladminbackend.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：郭立仁
 * 描述：永无BUG
 */
@RestController
@RequestMapping("cate")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("{page}/{pageSize}")
    public R selectAll(@PathVariable Integer page,@PathVariable Integer pageSize){
        return categoryService.selectAll(page,pageSize);
    }

    @GetMapping("{page}/{pageSize}/{id}")
    public R selectCate(@PathVariable Integer id,@PathVariable Integer page,@PathVariable Integer pageSize){
        return categoryService.selectCate(id,page,pageSize);
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id){
        return categoryService.deleteCateAndGrid(id);
    }

    @PutMapping
    public R update(@RequestBody GridCategory gridCategory){
        return categoryService.updateGrid(gridCategory);
    }

    @PostMapping
    public R insertGrid(@RequestBody GridCategory gridCategory){
        return categoryService.insertGrid(gridCategory);
    }

    @DeleteMapping("son/{id}")
    public R delCate(@PathVariable Integer id){
        return categoryService.delCate(id);
    }

    @PutMapping("son")
    public R update(@RequestBody Category category){
        return categoryService.updateCate(category);
    }

    @PostMapping("son")
    public R insertCate(@RequestBody Category category){
        return categoryService.insertCate(category);
    }

    @GetMapping("all")
    public R allCateGory(){
        return  categoryService.allCategory();
    }
}
